package com.fish.admin.module.tenant.controller;

import com.fish.admin.module.tenant.domain.dto.TenantInfoDTO;
import com.fish.admin.module.tenant.domain.dto.TenantInfoPageQueryDTO;
import com.fish.admin.module.tenant.domain.dto.TenantInfoQuotaDTO;
import com.fish.admin.module.tenant.domain.dto.TenantInfoRatioDTO;
import com.fish.admin.module.tenant.domain.vo.TenantInfoVO;
import com.fish.admin.module.tenant.enums.*;
import com.fish.admin.module.tenant.service.TenantInfoService;
import com.fish.common.core.domain.vo.PageVO;
import com.fish.common.core.enums.EnabledEnum;
import com.fish.common.core.response.RestResponse;
import com.fish.common.core.validation.InsertDefaultGroup;
import com.fish.common.support.util.EnumUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/tenant/info")
public class TenantInfoController {

    private final TenantInfoService  tenantInfoService;

    /**
     * 分页获取渠道
     * @param tenantInfoPageQueryDTO
     * @return
     */
    @PostMapping("/v1/page")
    public RestResponse<PageVO<TenantInfoVO>> page(
            @RequestBody TenantInfoPageQueryDTO tenantInfoPageQueryDTO) {
        return RestResponse.ok(tenantInfoService.page(tenantInfoPageQueryDTO));
    }

    /**
     * 新增
     * @param tenantInfoDTO
     * @return
     */
    @PostMapping("/v1/save")
    public RestResponse save(@RequestBody @Validated(InsertDefaultGroup.class) TenantInfoDTO tenantInfoDTO) {
        tenantInfoService.save(tenantInfoDTO);
        return RestResponse.ok();
    }



    /**
     * 渠道可用状态
     * @param id
     * @param enabled
     * @return
     */
    @PostMapping("/v1/changeEnabled/{id}/{enabled}")
    public RestResponse changeEnabled(@PathVariable Long id, @PathVariable Integer enabled) {
        tenantInfoService.changeEnabled(id, EnumUtils.getEnum(enabled, EnabledEnum.class));
        return RestResponse.ok();
    }

    /**
     * 放款权限
     * @param id
     * @param loanAuth
     * @return
     */
    @PostMapping("/v1/changeLoanAuth/{id}/{loanAuth}")
    public RestResponse changeLoanAuth(@PathVariable Long id, @PathVariable Integer loanAuth) {
        tenantInfoService.changeLoanAuth(id, EnumUtils.getEnum(loanAuth, LoanAuthEnums.class));
        return RestResponse.ok();
    }

    /**
     * 上线分权限
     * @param id
     * @param upDownAuth
     * @return
     */
    @PostMapping("/v1/changeUpDownAuth/{id}/{upDownAuth}")
    public RestResponse changeUpDownAuth(@PathVariable Long id, @PathVariable Integer upDownAuth) {
        tenantInfoService.changeUpDownAuth(id, EnumUtils.getEnum(upDownAuth, UpDownAuthEnums.class));
        return RestResponse.ok();
    }

    /**
     * 自动配置偷人
     * @param id
     * @param stealStatus
     * @return
     */
    @PostMapping("/v1/changeStealStatus/{id}/{stealStatus}")
    public RestResponse changeStealStatus(@PathVariable Long id, @PathVariable Integer stealStatus) {
        tenantInfoService.changeStealStatus(id, EnumUtils.getEnum(stealStatus, StealStatusEnums.class));
        return RestResponse.ok();
    }

    /**
     * 宝箱活动
     * @param id
     * @param boxActivity
     * @return
     */
    @PostMapping("/v1/changeBoxActivity/{id}/{boxActivity}")
    public RestResponse changeBoxActivity(@PathVariable Long id, @PathVariable Integer boxActivity) {
        tenantInfoService.changeBoxActivity(id, EnumUtils.getEnum(boxActivity, BoxActivityEnums.class));
        return RestResponse.ok();
    }

    /**
     * 邀请活动
     * @param id
     * @param inviteReward
     * @return
     */
    @PostMapping("/v1/changeInviteReward/{id}/{inviteReward}")
    public RestResponse changeInviteReward(@PathVariable Long id, @PathVariable Integer inviteReward) {
        tenantInfoService.changeInviteReward(id, EnumUtils.getEnum(inviteReward, InviteRewardEnums.class));
        return RestResponse.ok();
    }
    @PostMapping("/v1/updateQuota/{id}")
    public RestResponse updateQuota(@PathVariable Long id,@RequestBody TenantInfoQuotaDTO tenantInfoQuotaDTO){
        tenantInfoService.updateQuota(id,tenantInfoQuotaDTO);
        return RestResponse.ok();
    }

    @PostMapping("/v1/updateRatio/{id}")
    public RestResponse updateRatio(@PathVariable Long id,@RequestBody TenantInfoRatioDTO techInfoRatioDTO){
        tenantInfoService.updateRatio(id,techInfoRatioDTO);
        return RestResponse.ok();
    }






}
